<<<<<<< HEAD
<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class MY_Controller extends CI_Controller {
	
	public $tab = '';
	public $sub = '';
	
	private $image_types = array (IMAGETYPE_GIF => 'gif', IMAGETYPE_JPEG => 'jpg', IMAGETYPE_PNG => 'png' );
	
	public function __construct() {
		parent::__construct ();
	}
	
	function init_account($user_id) {
		$this->load->model ( 'Account_model', 'account' );
		$account = $this->account->get_account ( $user_id );
		if (! $account) {
			$initAccount = array ('user_id' => $user_id, 'total' => '0', 'use_money' => '0', 'no_use_money' => '0', 'collection' => '0' );
			$this->account->init_account ( $initAccount );
		
		}
	}
	
	public function get_user_info($user_tab, $user_sub, $sub = '') {
		$user = $this->session->userdata ( 'rsh_user' );
		$this->load->model ( 'User_model', 'user' );
		$data ['user'] = $this->user->get_by_uid ( $user ['user_id'] );
		
		$this->load->model ( 'User_vip_model', 'user_vip' );
		$data ['user_vip'] = $this->user_vip->get_by_uid ( $user ['user_id'] );
		
		$this->init_account ( $user ['user_id'] );
		
		$data ['tab'] = $this->tab;
		$data ['sub'] = $sub ? $sub : $this->sub;
		$data ['user_tab'] = $user_tab;
		$data ['user_sub'] = $user_sub;
		
		return $data;
	}
	
	function sendsms($phone, $msg) {
		$this->load->library ( 'phone' );
		$res = $this->phone->send ( $phone, $msg );
		return $res;
	}

	//投资人回款短信提示
	function reUserMsg($data){
		$ret = $this->array_unique_fb($data);//去重复的投资人
		$this->load->model('User_model');
		foreach ($ret as $value) {
			$userinfo=$this->User_model->get_username_by_id($value[0]);
			if($userinfo!=null&&$value[1]!=null){
				$username=$userinfo['username'];
				$msgContent="亲爱的".$username."，您投资的一点投<".$value[1].">已到期回款，请您留意查看！";
				$this->sendsms($userinfo['phone'],$msgContent);
			}
		}
	}

	//投资人回款，短信发送去投资人重复值
	function array_unique_fb($array){
	    foreach ($array as $v){
	        $v = join(",",$v);  //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
	        $temp[] = $v;
	    }
	    $temp = array_unique($temp);    //去掉重复的字符串,也就是重复的一维数组
	    foreach ($temp as $k => $v){
	        $temp[$k] = explode(",",$v);   //再将拆开的数组重新组装
	    }
	    return $temp;
	}
	
	function notice_message($uid, $name, $content) {
		$this->load->model ( 'Message_model', 'message' );
		$msg = array ('sent_user' => 1, 'receive_user' => $uid, 'name' => $name, 'fstatus' => 0, 'message_type' => '1', 'sented' => 0, 'deltype' => 0, 'content' => $content, 'add_time' => time (), 'addip' => $this->input->ip_address () );
		$this->message->send ( $msg );
	}
	
	function notice_email($type = 1, $uid, $data = array()) {
		//$emailTxt = filePath('config/emailtxt');
		//$smsTxt = filePath("config/smstxt");
		//$msgTxt = filePath("config/msgtxt");
		

		$emailTxt = de_xie ( $emailTxt );
		$smsTxt = de_xie ( $smsTxt );
		
		$this->load->library ( 'func' );
		$this->load->model ( 'User_model', 'user' );
		$this->load->model ( 'Systemtemplet_model', 'system' );
		if ($uid > 0) {
			$minfo = $this->user->get_by_uid ( $uid );
			$username = $minfo ['username'];
			$user_id = $minfo ['user_id'];
			$webname = CON_PLATFORMNAME;
			$email = $minfo ['email'];
			$str = implode ( ',', array ($user_id, $username, $email, time () ) );
			
			$this->load->library ( '/phpmailer/PHPMailer' );
			$this->phpmailer->IsSMTP ();
			$this->phpmailer->AddAddress( $email,$username ); //收件人
		}
		else return '';
		
		switch ($type) {
			case 10 : //激活邮箱
				
				$active_id = urlencode ( $this->func->authcode ( $str, "ENCODE" ) );
				
				$weburl = "http://{$_SERVER['HTTP_HOST']}/reg/activation?act={$active_id}";
				$link = '<a href="' . $weburl . '" style="color:#91273d">点击链接验证邮件</a>';
				$regsuccess = $this->system->get_templet_obj ( 10 ); //取到激活邮箱模板
				

				/*邮件*/
				$subject = "您刚刚在" . $webname . "注册成功";
				$msgBody = str_replace ( array ("#UserName#", "#LINK#" ), array ($username, $link ), $regsuccess ['content'] );
				
			
				$this->phpmailer->Subject = $subject;
				$this->phpmailer->Body = $msgBody;
				$send = $this->phpmailer->Send();
				return $send;
				break;
			
			case 2 : //登陆密码找回发邮件
				$pactive_id = urlencode ( $this->func->authcode ( $str, "ENCODE", '', 3600 ) );
				$pweburl = "http://{$_SERVER['HTTP_HOST']}/password/getpwd?check=" . $pactive_id;
				$plink = '<a href="' . $pweburl . '" style="color:#91273d">点击链接找回密码</a>';
				/*邮件*/
				$findPwdMail = $this->system->get_templet_obj ( 12 ); //取到找回登录密码邮箱模板
				$subject = CON_PLATFORMNAME . "登陆密码找回";
				$msgBody = str_replace ( array ("#UserName#", "#LINK#" ), array ($username, $plink ), $findPwdMail ['content'] );
				$this->phpmailer->Subject = $subject;
				$this->phpmailer->Body = $msgBody;
				$send = $this->phpmailer->Send ();
				return $send;
				break;
			
			case 3 : //交易密码找回发邮件
				$payactive_id = urlencode ( $this->func->authcode ( $str, "ENCODE", '', 3600 ) );
				$payweburl = "http://{$_SERVER['HTTP_HOST']}/password/zhs_paypwd?check=" . $payactive_id;
				$paylink = '<a href="' . $payweburl . '" style="color:#91273d">点击链接找回交易密码</a>';
				$findPaypwdMail = $this->system->get_templet_obj ( 15 ); //取到找回交易密码邮箱模板
				/*邮件*/
				$subject = CON_PLATFORMNAME . "交易密码找回";
				$msgBody = str_replace ( array ("#UserName#", "#LINK#" ), array ($username, $paylink ), $findPaypwdMail ['content'] );
				$this->phpmailer->Subject = $subject;
				$this->phpmailer->Body = $msgBody;
				$send = $this->phpmailer->Send ();
				return $send;
				break;
			case 4 : //手机认证发送验证码：
				$vcode = $data ['vcode'];
				$verify_phone = $this->system->get_templet_obj ( 7 ); //取到手机验证码模板
				$content = str_replace ( array ("#key_code#" ), array ($vcode ), $verify_phone ['content'] );
				$send = $this->sendsms ( $data ['phone'], $content );
				return $send;
				break;
			case 5 : //线上充值成功
				$vmoney = $data ['money'];
				$payonline = $this->system->get_templet_obj ( 7 ); //取到手机充值模板
				$content = str_replace ( array ("#MONEY#" ), array ($vmoney ), $payonline ['content'] );
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			
			case 6 : //还款到账
				$borrow_id = $data ['borrow_id'];
				$borrow_order = $data ['forder'];
				$content = str_replace ( array ("#ID#", "#ORDER#" ), array ($borrow_id, $borrow_order ), $smsTxt ['payback'] );
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 7 : //提现成功
				$vdate = $data ['vdate'];
				$vmoney = $data ['vmoney'];
				$vcredit = $data ['vcredit'];
				$vfee = $data ['vfee'];
				$content = str_replace ( array ("#DATE#", "#WITHDRAWMONEY#", "CREDITED", "FEE" ), array ($vdate, $vmoney, $vcredit, $vfee ), $smsTxt ['withdraw'] );
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 8 : //VIP认证通过
				$content = $smsTxt ['vip'];
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 9 : //发标初审通过
				$content = $smsTxt ['firstV'];
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 10 : //发标复审通过
				$content = $smsTxt ['approve'];
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 11 : //更改旧邮箱验证码：
				$active_id = rand_string ( $str, 10, 3, 13 );
				$this->session->set_userdata ( 'zhsjr_active_id__email', $active_id );
				$regsuccess = $this->system->get_templet_obj ( 11 ); //取到激活邮箱模板
				/*邮件*/
				$subject = "您刚刚在" . $webname . "更改旧邮箱";
				$msgBody = str_replace ( array ("#UserName#", "#ACTIVE_ID#" ), array ($username, $active_id ), $regsuccess ['content'] );
				$this->phpmailer->Subject = $subject;
				$this->phpmailer->Body = $msgBody;
				$send = $this->phpmailer->Send ();
				return $send;
				break;
		
		}
	}
	
	function notice_credit($user_id, $nid) {
		$this->load->model ( 'Credit_model', 'credit' );
		$credit_info = $this->credit->get_credit_rule ( array ('nid' => $nid ) );
		$creditlog = array ('user_id' => $user_id, 'type_id' => $credit_info ['id'], 'op' => 1, //变动类型,1:增加,2:减少
'credit_value' => $credit_info ['credit_value'], 'remark' => $credit_info ['name'] . '送积分', 'op_user' => 1, 'add_time' => time (), 'addip' => $this->input->ip_address () );
		$this->credit->incr_credit ( $creditlog );
	}
	
	/*
	 * 上传图片
	 */
	function upload_thumbnail($path, $thumbnail, $file, $warter = 0) {
		if (! file_exists ( $path )) {
			mkdir ( $path, 0777 );
		}
		
		$config ['upload_path'] = $path;
		$config ['allowed_types'] = 'gif|jpg|png';
		$config ['file_name'] = $file . uniqid ();
		$config ['overwrite'] = true;
		$config ['max_size'] = '812';
		$config ['max_width'] = '2048';
		$config ['max_height'] = '3000';
		$this->load->library ( 'upload', $config );
		if ($this->upload->do_upload ( 'thumbnail' )) {
			
			$tmp = $this->upload->data ();
			$thumbnail = $thumbnail . $config ['file_name'] . $tmp ['file_ext'];
			
			//添加水印	
			if ($warter > 0) {
				$this->load->library ( 'image_lib' );
				$warter ['source_image'] = $thumbnail;
				$warter ['wm_type'] = 'overlay';
				$warter ['wm_overlay_path'] = WM_OVERLAY_FILE_PNG;
				$warter ['wm_opacity'] = '60';
				$warter['wm_vrt_alignment'] = 'B';// 底部
				$warter['wm_hor_alignment'] = 'R';// 右边
				$this->image_lib->initialize ( $warter );
				$this->image_lib->watermark ();
			}
			
			return $thumbnail;
		} else {
			$ret ['url'] = 'error';
			$ret ['msg'] = $this->upload->display_errors ();
			echo json_encode ( $ret );
			exit ();
		}
	
	}
	
	public function attach($path, $tmp_name, $file_name, $format) {
		// $is_image = $this->is_valid_image($file);
		if ($format == 1) {
			$thumbnail = $this->wrap_image ( $path );
		} else if (in_array ( $format, array (3, 4 ) )) {
			$thumbnail = $this->wrap_videoembed ( $path, $tmp_name, $file_name );
		} else {
			$thumbnail = $this->wrap_file ( $path, $tmp_name, $file_name );
		}
		return $thumbnail;
	
	}
	
	public function wrap_image($source) {
		if (! file_exists ( $source )) {
			mkdir ( $source, 0777 );
		}
		
		$config ['upload_path'] = $source;
		$config ['allowed_types'] = 'gif|jpg|png';
		$config ['file_name'] = 'conset_pic_' . uniqid ();
		$config ['overwrite'] = true;
		$config ['max_size'] = '512';
		$config ['max_width'] = '2048';
		$config ['max_height'] = '3000';
		$this->load->library ( 'upload', $config );
		if ($this->upload->do_upload ( 'thumbnail' )) {
			$tmp = $this->upload->data ();
			$thumbnail = $config ['file_name'] . $tmp ['file_ext'];
			return $thumbnail;
		} else {
			/*$ret['url'] = 'error';
			$ret['msg'] = $this->upload->display_errors();
			echo json_encode($ret);exit;*/
			return false;
		}
	}
	
	public function wrap_file($source, $tmp_name, $filename) {
		if (! file_exists ( $source )) {
			mkdir ( $$source, 0777 );
		}
		
		$ext = '';
		$pos = mb_strrpos ( $filename, '.' );
		
		if (FALSE !== $pos) {
			$ext = '.' . mb_strtolower ( mb_substr ( $filename, $pos + 1 ) );
		}
		
		$data = array ('attach_type' => 'file', 'title' => $filename, 'file_thumbnail' => 'conset_file_' . time () . rand ( 100000, 999999 ) . $ext, 'filesize' => 0 );
		
		move_uploaded_file ( $tmp_name, $source . $data ['file_thumbnail'] );
		$data ['filesize'] = filesize ( $source . $data ['file_thumbnail'] );
		return $data ['file_thumbnail'];
	
	}
	
	public function wrap_videoembed($source) {
		$config ['upload_path'] = $source;
		$config ['allowed_types'] = 'mov|mpeg|mp3|mp4|avi|flv|rmvb';
		$config ['max_size'] = '50000';
		$config ['max_width'] = '';
		$config ['max_height'] = '';
		$this->load->library ( 'upload', $config );
		
		if (! $this->upload->do_upload ( 'thumbnail' )) {
			$err_msgs .= 'Error in Uploading video ' . $this->upload->display_errors () . '<br />';
			$ret ['msg'] = $err_msgs;
			echo json_encode ( $ret );
			exit ();
		} else {
			
			$data = array ('upload_data' => $this->upload->data () );
			$video_path = $data ['upload_data'] ['file_name'];
			$directory_path = $data ['upload_data'] ['file_path'];
			$directory_path_full = $data ['upload_data'] ['full_path'];
			//$file_name = $data['upload_data']['raw_name'];
			$file_name = 'conset_video_' . uniqid ();
			exec ( "ffmpeg -i " . $directory_path_full . " " . $directory_path . $file_name . ".flv" );
			return $file_name . '.' . 'flv';
		}
	}
	
	public function is_valid_image($filename) {
		$pos = mb_strrpos ( $filename, '.' );
		if ($pos) {
			$ext = mb_strtolower ( mb_substr ( $filename, $pos + 1 ) );
		} else {
			$ext = $filename;
		}
		
		if (in_array ( $ext, $this->image_types )) {
			return TRUE;
		}
		
		return FALSE;
	}
	
	/**
	 * 
	 * 储存模板内容
	 * @param $data
	 */
	function user_send_add($data) {
		$this->load->model ( 'Systemtemplet_model' );
		$this->Systemtemplet_model->user_send_add ( $data );
	}
	
	/**
	 * 
	 * 发送站内信
	 * @param $subject  站内信标题
	 * @param $templetBody  站内信内容
	 * @param $uid 用户ID
	 */
	function send_msg($data) {
		$this->load->model ( 'Systemtemplet_model', 'system' );
		$obj = $this->system->get_templet_obj ( $data['sys_id']);
		$uid = $data ['user_id'];
		
		if ($obj && $uid > 0) {
			$subject = $obj ['title'];
			$templetBody = $obj ['content'];
			$this->load->model ( 'User_model', 'user' );
			
			$minfo = $this->user->get_by_uid ( $uid );
			unset($data ['user_id']);
			unset($data['sys_id']);

			$arr0 = array(0=>"#username#");
			$arr1 = array(0=>$minfo ['username']);
			$i = 1;
			foreach($data as $key => $val){
				$arr0[$i] = "#".$key."#";
				$arr1[$i] = $val;
				$i++;
			}
			
			$msgBody = str_replace ( $arr0,$arr1, $templetBody);
			
			$this->load->model ( 'Message_model', 'message' );
			$msg = array ('sent_user' => 1, 'receive_user' => $uid, 'name' => $subject, 'fstatus' => 0, 'message_type' => 'system', 'sented' => 0, 'deltype' => 0, 'content' => $msgBody, 'add_time' => time (), 'addip' => $this->input->ip_address () );
			
			$send = $this->message->send ( $msg );
			
			if ($send > 0) {
				$data ['status'] = 1;
			}
			
			//$data ['content'] = $msgBody;
			//$this->user_send_add ( $data );
			
			return $send;
		}
	}
	
	/**
	 * 
	 * 发送短信
	 * @param $templetBody  短信内容
	 * @param $uid 用户ID
	 */
	/*function send_sms($data) {
		$uid = $data ['user_id'];
		
		$templetBody = $data ['content'];
		
		$this->load->library ( 'phone' );
		$this->load->model ( 'User_model', 'user' );
		
		$minfo = $this->user->get_by_uid ( $uid );
		if ($minfo ['phone']) {
			$username = $minfo ['username'];
			$msgBody = str_replace ( array ("#UserName#" ), array ($username ), $templetBody );
			$send = $this->phone->send ( $minfo ['phone'], $msgBody );
			$send = ( array ) $send;
			if ($send [0] == 0) {
				$data ['status'] = 1;
			}
			$data ['content'] = $msgBody;
			$this->user_send_add ( $data );
			return $send [0];
		} else {
			return 0;
		}
	}*/
	
	/**
	 * 
	 * 发送邮件
	 * @param $subject  邮件标题
	 * @param $templetBody  邮件内容
	 * @param $uid 用户ID
	 */
	function send_email($data) {
		
		$uid = $data ['user_id'];
		$subject = $data ['title'];
		$templetBody = $data ['content'];
		
		$this->load->model ( 'User_model', 'user' );
		if ($uid > 0) {
			$minfo = $this->user->get_by_uid ( $uid );
			$username = $minfo ['username'];
			$user_id = $minfo ['user_id'];
			$webname = CON_PLATFORMNAME;
			$email = $minfo ['email'];
			$str = implode ( ',', array ($user_id, $username, $email ) );
			
			$this->load->library ( '/phpmailer/PHPMailer' );
			$this->phpmailer->IsSMTP ();
			$this->phpmailer->AddAddress ( $email, $username ); //收件人
			

			$msgBody = str_replace ( array ("#UserName#" ), array ($username ), $templetBody );
			$this->phpmailer->Subject = $subject;
			$this->phpmailer->Body = $msgBody;
			$send = $this->phpmailer->Send ();
			
			if ($send > 0) {
				$data ['status'] = 1;
			}
			//$data ['content'] = $msgBody;
			//$this->user_send_add ( $data );
			
			return $send;
		}
	
	}
	
	//投标成功协议内容
	/**
	 * 
	 * @param $title  邮件标题
	 * @param $content  邮件内容
	 * @param $uid 用户ID
	 * 20150820
	 */
	function send_xieyi($data){
		
	}

}
=======
<?php
if (! defined ( 'BASEPATH' ))
    exit ( 'No direct script access allowed' );

class MY_Controller extends CI_Controller {
	
	public $tab = '';
	public $sub = '';
	
	private $image_types = array (IMAGETYPE_GIF => 'gif', IMAGETYPE_JPEG => 'jpg', IMAGETYPE_PNG => 'png' );
	
	public function __construct() {
		parent::__construct ();
	}
	
	function init_account($user_id) {
		$this->load->model ( 'Account_model', 'account' );
		$account = $this->account->get_account ( $user_id );
		if (! $account) {
			$initAccount = array ('user_id' => $user_id, 'total' => '0', 'use_money' => '0', 'no_use_money' => '0', 'collection' => '0' );
			$this->account->init_account ( $initAccount );
		
		}
	}
	
	public function get_user_info($user_tab, $user_sub, $sub = '') {
		$user = $this->session->userdata ( 'rsh_user' );
		$this->load->model ( 'User_model', 'user' );
		$data ['user'] = $this->user->get_by_uid ( $user ['user_id'] );
		
		$this->load->model ( 'User_vip_model', 'user_vip' );
		$data ['user_vip'] = $this->user_vip->get_by_uid ( $user ['user_id'] );
		
		$this->init_account ( $user ['user_id'] );
		
		$data ['tab'] = $this->tab;
		$data ['sub'] = $sub ? $sub : $this->sub;
		$data ['user_tab'] = $user_tab;
		$data ['user_sub'] = $user_sub;
		
		return $data;
	}
	
	function sendsms($phone, $msg) {
		$this->load->library ( 'phone' );
		$res = $this->phone->send ( $phone, $msg );
		return $res;
	}
	
	function notice_message($uid, $name, $content) {
		$this->load->model ( 'Message_model', 'message' );
		$msg = array ('sent_user' => 1, 'receive_user' => $uid, 'name' => $name, 'fstatus' => 0, 'message_type' => '1', 'sented' => 0, 'deltype' => 0, 'content' => $content, 'add_time' => time (), 'addip' => $this->input->ip_address () );
		$this->message->send ( $msg );
	}
	
	function notice_email($type = 1, $uid, $data = array()) {
		//$emailTxt = filePath('config/emailtxt');
		//$smsTxt = filePath("config/smstxt");
		//$msgTxt = filePath("config/msgtxt");
		

		$emailTxt = de_xie ( $emailTxt );
		$smsTxt = de_xie ( $smsTxt );
		
		$this->load->library ( 'func' );
		$this->load->model ( 'User_model', 'user' );
		$this->load->model ( 'Systemtemplet_model', 'system' );
		if ($uid > 0) {
			$minfo = $this->user->get_by_uid ( $uid );
			$username = $minfo ['username'];
			$user_id = $minfo ['user_id'];
			$webname = CON_PLATFORMNAME;
			$email = $minfo ['email'];
			$str = implode ( ',', array ($user_id, $username, $email, time () ) );
			
			$this->load->library ( '/phpmailer/PHPMailer' );
			$this->phpmailer->IsSMTP ();
			$this->phpmailer->AddAddress( $email,$username ); //收件人
		}
		else return '';
		
		switch ($type) {
			case 10 : //激活邮箱
				
				$active_id = urlencode ( $this->func->authcode ( $str, "ENCODE" ) );
				
				$weburl = "http://{$_SERVER['HTTP_HOST']}/reg/activation?act={$active_id}";
				$link = '<a href="' . $weburl . '" style="color:#91273d">点击链接验证邮件</a>';
				$regsuccess = $this->system->get_templet_obj ( 10 ); //取到激活邮箱模板
				

				/*邮件*/
				$subject = "您刚刚在" . $webname . "注册成功";
				$msgBody = str_replace ( array ("#UserName#", "#LINK#" ), array ($username, $link ), $regsuccess ['content'] );
				
			
				$this->phpmailer->Subject = $subject;
				$this->phpmailer->Body = $msgBody;
				$send = $this->phpmailer->Send();
				return $send;
				break;
			
			case 2 : //登陆密码找回发邮件
				$pactive_id = urlencode ( $this->func->authcode ( $str, "ENCODE", '', 3600 ) );
				$pweburl = "http://{$_SERVER['HTTP_HOST']}/password/getpwd?check=" . $pactive_id;
				$plink = '<a href="' . $pweburl . '" style="color:#91273d">点击链接找回密码</a>';
				/*邮件*/
				$findPwdMail = $this->system->get_templet_obj ( 12 ); //取到找回登录密码邮箱模板
				$subject = CON_PLATFORMNAME . "登陆密码找回";
				$msgBody = str_replace ( array ("#UserName#", "#LINK#" ), array ($username, $plink ), $findPwdMail ['content'] );
				$this->phpmailer->Subject = $subject;
				$this->phpmailer->Body = $msgBody;
				$send = $this->phpmailer->Send ();
				return $send;
				break;
			
			case 3 : //交易密码找回发邮件
				$payactive_id = urlencode ( $this->func->authcode ( $str, "ENCODE", '', 3600 ) );
				$payweburl = "http://{$_SERVER['HTTP_HOST']}/password/zhs_paypwd?check=" . $payactive_id;
				$paylink = '<a href="' . $payweburl . '" style="color:#91273d">点击链接找回交易密码</a>';
				$findPaypwdMail = $this->system->get_templet_obj ( 15 ); //取到找回交易密码邮箱模板
				/*邮件*/
				$subject = CON_PLATFORMNAME . "交易密码找回";
				$msgBody = str_replace ( array ("#UserName#", "#LINK#" ), array ($username, $paylink ), $findPaypwdMail ['content'] );
				$this->phpmailer->Subject = $subject;
				$this->phpmailer->Body = $msgBody;
				$send = $this->phpmailer->Send ();
				return $send;
				break;
			case 4 : //手机认证发送验证码：
				$vcode = $data ['vcode'];
				$verify_phone = $this->system->get_templet_obj ( 7 ); //取到手机验证码模板
				$content = str_replace ( array ("#key_code#" ), array ($vcode ), $verify_phone ['content'] );
				$send = $this->sendsms ( $data ['phone'], $content );
				return $send;
				break;
			case 5 : //线上充值成功
				$vmoney = $data ['money'];
				$payonline = $this->system->get_templet_obj ( 7 ); //取到手机充值模板
				$content = str_replace ( array ("#MONEY#" ), array ($vmoney ), $payonline ['content'] );
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			
			case 6 : //还款到账
				$borrow_id = $data ['borrow_id'];
				$borrow_order = $data ['forder'];
				$content = str_replace ( array ("#ID#", "#ORDER#" ), array ($borrow_id, $borrow_order ), $smsTxt ['payback'] );
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 7 : //提现成功
				$vdate = $data ['vdate'];
				$vmoney = $data ['vmoney'];
				$vcredit = $data ['vcredit'];
				$vfee = $data ['vfee'];
				$content = str_replace ( array ("#DATE#", "#WITHDRAWMONEY#", "CREDITED", "FEE" ), array ($vdate, $vmoney, $vcredit, $vfee ), $smsTxt ['withdraw'] );
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 8 : //VIP认证通过
				$content = $smsTxt ['vip'];
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 9 : //发标初审通过
				$content = $smsTxt ['firstV'];
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 10 : //发标复审通过
				$content = $smsTxt ['approve'];
				$send = $this->sendsms ( $minfo ['phone'], $content );
				return $send;
				break;
			case 11 : //更改旧邮箱验证码：
				$active_id = rand_string ( $str, 10, 3, 13 );
				$this->session->set_userdata ( 'zhsjr_active_id__email', $active_id );
				$regsuccess = $this->system->get_templet_obj ( 11 ); //取到激活邮箱模板
				/*邮件*/
				$subject = "您刚刚在" . $webname . "更改旧邮箱";
				$msgBody = str_replace ( array ("#UserName#", "#ACTIVE_ID#" ), array ($username, $active_id ), $regsuccess ['content'] );
				$this->phpmailer->Subject = $subject;
				$this->phpmailer->Body = $msgBody;
				$send = $this->phpmailer->Send ();
				return $send;
				break;
		
		}
	}
	
	function notice_credit($user_id, $nid) {
		$this->load->model ( 'Credit_model', 'credit' );
		$credit_info = $this->credit->get_credit_rule ( array ('nid' => $nid ) );
		$creditlog = array ('user_id' => $user_id, 'type_id' => $credit_info ['id'], 'op' => 1, //变动类型,1:增加,2:减少
'credit_value' => $credit_info ['credit_value'], 'remark' => $credit_info ['name'] . '送积分', 'op_user' => 1, 'add_time' => time (), 'addip' => $this->input->ip_address () );
		$this->credit->incr_credit ( $creditlog );
	}
	
	/*
	 * 上传图片
	 */
	function upload_thumbnail($path, $thumbnail, $file, $warter = 0) {
		if (! file_exists ( $path )) {
			mkdir ( $path, 0777 );
		}
		
		$config ['upload_path'] = $path;
		$config ['allowed_types'] = 'gif|jpg|png';
		$config ['file_name'] = $file . uniqid ();
		$config ['overwrite'] = true;
		$config ['max_size'] = '812';
		$config ['max_width'] = '2048';
		$config ['max_height'] = '3000';
		$this->load->library ( 'upload', $config );
		if ($this->upload->do_upload ( 'thumbnail' )) {
			
			$tmp = $this->upload->data ();
			$thumbnail = $thumbnail . $config ['file_name'] . $tmp ['file_ext'];
			
			//添加水印	
			if ($warter > 0) {
				$this->load->library ( 'image_lib' );
				$warter ['source_image'] = $thumbnail;
				$warter ['wm_type'] = 'overlay';
				$warter ['wm_overlay_path'] = WM_OVERLAY_FILE_PNG;
				$warter ['wm_opacity'] = '60';
				$warter['wm_vrt_alignment'] = 'B';// 底部
				$warter['wm_hor_alignment'] = 'R';// 右边
				$this->image_lib->initialize ( $warter );
				$this->image_lib->watermark ();
			}
			
			return $thumbnail;
		} else {
			$ret ['url'] = 'error';
			$ret ['msg'] = $this->upload->display_errors ();
			echo json_encode ( $ret );
			exit ();
		}
	
	}
	
	public function attach($path, $tmp_name, $file_name, $format) {
		// $is_image = $this->is_valid_image($file);
		if ($format == 1) {
			$thumbnail = $this->wrap_image ( $path );
		} else if (in_array ( $format, array (3, 4 ) )) {
			$thumbnail = $this->wrap_videoembed ( $path, $tmp_name, $file_name );
		} else {
			$thumbnail = $this->wrap_file ( $path, $tmp_name, $file_name );
		}
		return $thumbnail;
	
	}
	
	public function wrap_image($source) {
		if (! file_exists ( $source )) {
			mkdir ( $source, 0777 );
		}
		
		$config ['upload_path'] = $source;
		$config ['allowed_types'] = 'gif|jpg|png';
		$config ['file_name'] = 'conset_pic_' . uniqid ();
		$config ['overwrite'] = true;
		$config ['max_size'] = '512';
		$config ['max_width'] = '2048';
		$config ['max_height'] = '3000';
		$this->load->library ( 'upload', $config );
		if ($this->upload->do_upload ( 'thumbnail' )) {
			$tmp = $this->upload->data ();
			$thumbnail = $config ['file_name'] . $tmp ['file_ext'];
			return $thumbnail;
		} else {
			/*$ret['url'] = 'error';
			$ret['msg'] = $this->upload->display_errors();
			echo json_encode($ret);exit;*/
			return false;
		}
	}
	
	public function wrap_file($source, $tmp_name, $filename) {
		if (! file_exists ( $source )) {
			mkdir ( $$source, 0777 );
		}
		
		$ext = '';
		$pos = mb_strrpos ( $filename, '.' );
		
		if (FALSE !== $pos) {
			$ext = '.' . mb_strtolower ( mb_substr ( $filename, $pos + 1 ) );
		}
		
		$data = array ('attach_type' => 'file', 'title' => $filename, 'file_thumbnail' => 'conset_file_' . time () . rand ( 100000, 999999 ) . $ext, 'filesize' => 0 );
		
		move_uploaded_file ( $tmp_name, $source . $data ['file_thumbnail'] );
		$data ['filesize'] = filesize ( $source . $data ['file_thumbnail'] );
		return $data ['file_thumbnail'];
	
	}
	
	public function wrap_videoembed($source) {
		$config ['upload_path'] = $source;
		$config ['allowed_types'] = 'mov|mpeg|mp3|mp4|avi|flv|rmvb';
		$config ['max_size'] = '50000';
		$config ['max_width'] = '';
		$config ['max_height'] = '';
		$this->load->library ( 'upload', $config );
		
		if (! $this->upload->do_upload ( 'thumbnail' )) {
			$err_msgs .= 'Error in Uploading video ' . $this->upload->display_errors () . '<br />';
			$ret ['msg'] = $err_msgs;
			echo json_encode ( $ret );
			exit ();
		} else {
			
			$data = array ('upload_data' => $this->upload->data () );
			$video_path = $data ['upload_data'] ['file_name'];
			$directory_path = $data ['upload_data'] ['file_path'];
			$directory_path_full = $data ['upload_data'] ['full_path'];
			//$file_name = $data['upload_data']['raw_name'];
			$file_name = 'conset_video_' . uniqid ();
			exec ( "ffmpeg -i " . $directory_path_full . " " . $directory_path . $file_name . ".flv" );
			return $file_name . '.' . 'flv';
		}
	}
	
	public function is_valid_image($filename) {
		$pos = mb_strrpos ( $filename, '.' );
		if ($pos) {
			$ext = mb_strtolower ( mb_substr ( $filename, $pos + 1 ) );
		} else {
			$ext = $filename;
		}
		
		if (in_array ( $ext, $this->image_types )) {
			return TRUE;
		}
		
		return FALSE;
	}
	
	/**
	 * 
	 * 储存模板内容
	 * @param $data
	 */
	function user_send_add($data) {
		$this->load->model ( 'Systemtemplet_model' );
		$this->Systemtemplet_model->user_send_add ( $data );
	}
	
	/**
	 * 
	 * 发送站内信
	 * @param $subject  站内信标题
	 * @param $templetBody  站内信内容
	 * @param $uid 用户ID
	 */
	function send_msg($data) {
		$this->load->model ( 'Systemtemplet_model', 'system' );
		$obj = $this->system->get_templet_obj ( $data['sys_id']);
		$uid = $data ['user_id'];
		
		if ($obj && $uid > 0) {
			$subject = $obj ['title'];
			$templetBody = $obj ['content'];
			$this->load->model ( 'User_model', 'user' );
			
			$minfo = $this->user->get_by_uid ( $uid );
			unset($data ['user_id']);
			unset($data['sys_id']);

			$arr0 = array(0=>"#username#");
			$arr1 = array(0=>$minfo ['username']);
			$i = 1;
			foreach($data as $key => $val){
				$arr0[$i] = "#".$key."#";
				$arr1[$i] = $val;
				$i++;
			}
			
			$msgBody = str_replace ( $arr0,$arr1, $templetBody);
			
			$this->load->model ( 'Message_model', 'message' );
			$msg = array ('sent_user' => 1, 'receive_user' => $uid, 'name' => $subject, 'fstatus' => 0, 'message_type' => 'system', 'sented' => 0, 'deltype' => 0, 'content' => $msgBody, 'add_time' => time (), 'addip' => $this->input->ip_address () );
			
			$send = $this->message->send ( $msg );
			
			if ($send > 0) {
				$data ['status'] = 1;
			}
			
			//$data ['content'] = $msgBody;
			//$this->user_send_add ( $data );
			
			return $send;
		}
	}
	
	/**
	 * 
	 * 发送短信
	 * @param $templetBody  短信内容
	 * @param $uid 用户ID
	 */
	/*function send_sms($data) {
		$uid = $data ['user_id'];
		
		$templetBody = $data ['content'];
		
		$this->load->library ( 'phone' );
		$this->load->model ( 'User_model', 'user' );
		
		$minfo = $this->user->get_by_uid ( $uid );
		if ($minfo ['phone']) {
			$username = $minfo ['username'];
			$msgBody = str_replace ( array ("#UserName#" ), array ($username ), $templetBody );
			$send = $this->phone->send ( $minfo ['phone'], $msgBody );
			$send = ( array ) $send;
			if ($send [0] == 0) {
				$data ['status'] = 1;
			}
			$data ['content'] = $msgBody;
			$this->user_send_add ( $data );
			return $send [0];
		} else {
			return 0;
		}
	}*/
	
	/**
	 * 
	 * 发送邮件
	 * @param $subject  邮件标题
	 * @param $templetBody  邮件内容
	 * @param $uid 用户ID
	 */
	function send_email($data) {
		
		$uid = $data ['user_id'];
		$subject = $data ['title'];
		$templetBody = $data ['content'];
		
		$this->load->model ( 'User_model', 'user' );
		if ($uid > 0) {
			$minfo = $this->user->get_by_uid ( $uid );
			$username = $minfo ['username'];
			$user_id = $minfo ['user_id'];
			$webname = CON_PLATFORMNAME;
			$email = $minfo ['email'];
			$str = implode ( ',', array ($user_id, $username, $email ) );
			
			$this->load->library ( '/phpmailer/PHPMailer' );
			$this->phpmailer->IsSMTP ();
			$this->phpmailer->AddAddress ( $email, $username ); //收件人
			

			$msgBody = str_replace ( array ("#UserName#" ), array ($username ), $templetBody );
			$this->phpmailer->Subject = $subject;
			$this->phpmailer->Body = $msgBody;
			$send = $this->phpmailer->Send ();
			
			if ($send > 0) {
				$data ['status'] = 1;
			}
			//$data ['content'] = $msgBody;
			//$this->user_send_add ( $data );
			
			return $send;
		}
	
	}

}
>>>>>>> d47623b610d79a4eeb489500830c00d70933f414
